package mapEditor.view.mapEdit
{
	import flash.events.Event;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.Point;
	import flash.text.TextField;
	
	import iso.IsoBox;
	import iso.IsoPoint;
	import iso.IsoUtils;
	
	import mapEditor.data.ConfigTemplateInfo;
	import mapEditor.vo.MapTerrainTileVO;
	
	import utils.ColorMatrix;

	public class MapTerrainTileView extends IsoBox
	{
		private var _mapTerrainTileVO:MapTerrainTileVO;
		private var _txtTest:TextField;
		
		public function MapTerrainTileView(mapTerrainTileVO:MapTerrainTileVO)
		{
			_mapTerrainTileVO=mapTerrainTileVO;
			_mapTerrainTileVO.addEventListener(Event.CHANGE, __onTerrainTileVOChange);
			
			super(ConfigTemplateInfo.instance.mapVO.tileSize, _mapTerrainTileVO.height);

			isoPoint=new IsoPoint(_mapTerrainTileVO.x*ConfigTemplateInfo.instance.mapVO.tileSize, -_mapTerrainTileVO.bottom, _mapTerrainTileVO.y*ConfigTemplateInfo.instance.mapVO.tileSize);
			_txtTest=new TextField();
			_txtTest.height=20;
			_txtTest.width=20;
			_txtTest.x=5;
			_txtTest.y=5;
			addChild(_txtTest);
		}
		
		private function __onTerrainTileVOChange(evt:Event):void
		{
			height=_mapTerrainTileVO.height;
			var ipt:IsoPoint=new IsoPoint(_mapTerrainTileVO.x*ConfigTemplateInfo.instance.mapVO.tileSize, -_mapTerrainTileVO.bottom, _mapTerrainTileVO.y*ConfigTemplateInfo.instance.mapVO.tileSize);
			isoPoint=ipt;
			
			if(_mapTerrainTileVO.selected)
			{
				filters=[];
				filterTerrainTileView();
			}
			else
			{
				filters=[];
			}
			update();
		}
		
		private function filterTerrainTileView():void
		{
			var colorMatrixFilter:ColorMatrixFilter=new ColorMatrixFilter();
			var colorMatrix:ColorMatrix=new ColorMatrix();
			colorMatrix.adjustBrightness(-50);
			colorMatrixFilter.matrix=colorMatrix;
			filters=[colorMatrixFilter];
		}
		
		override public function dispose():void
		{
			_mapTerrainTileVO.removeEventListener(Event.CHANGE, __onTerrainTileVOChange);
			_mapTerrainTileVO=null;
			super.dispose();
		}

		public function get mapTerrainTileVO():MapTerrainTileVO
		{
			return _mapTerrainTileVO;
		}

		public function get txtTest():TextField
		{
			return _txtTest;
		}
	}
}